﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using ASPItalia.ModelVirtualCasting.Silverlight.BackOffice.ViewModels;
using ASPItalia.ModelVirtualCasting.Web.RiaServices;
using System.IO;
using System.Windows.Media.Imaging;
using Uploader;

namespace ASPItalia.ModelVirtualCasting.Silverlight.BackOffice.Views
{
  public partial class PeopleDetails : ViewChildWindowBase
  {
    public PeopleDetails()
    {
      InitializeComponent();
    }

    public PeopleDetails(People item)
      : this()
    {
      this.ViewModel.Item = item;
    }

    private new PeopleDetailsViewModel ViewModel
    {
      get
      {
        return (PeopleDetailsViewModel)base.ViewModel;
      }
    }

    private void OKButton_Click(object sender, RoutedEventArgs e)
    {
      df1.CommitEdit();
      this.DialogResult = true;
      ViewModel.UpdateCommand.Execute(null);
    }

    private void CancelButton_Click(object sender, RoutedEventArgs e)
    {
      df1.CancelEdit();
      this.DialogResult = false;
    }

    private void MultimediaList_Drop(object sender, DragEventArgs e)
    {
      IDataObject _data = e.Data;
      FileInfo[] _files = (FileInfo[])_data.GetData(DataFormats.FileDrop);

      UploadingChildWindow _upc = new UploadingChildWindow(_files);

      _upc.Closed += new EventHandler((o, ev) =>
      {
        foreach (FileInfo _fi in _files)
        {
          Multimedia newImage = new Multimedia() { FileName = _fi.Name, MultimediaType = "I", FileMimeType = "images/jpg" };
          ViewModel.Multimedias.Add(newImage);

          ViewModel.Item.Multimedia.Add(newImage);
        }
      });

      _upc.Show();
    }

    private void ViewChildWindowBase_Drop(object sender, DragEventArgs e)
    {
    }
  }
}

